<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>

    window.chatwootSettings = {
        hideMessageBubble: false,
        position: 'right',
        locale: 'en',
        type: 'standard',
        showPopoutButton: true,
        // 启用 localStorage 存储会话
        persistConversation: true, // 关键选项
    };

    (function (d, t) {
        var BASE_URL = "http://52.0.39.212:3000";
        var g = d.createElement(t), s = d.getElementsByTagName(t)[0];
        g.src = BASE_URL + "/packs/js/sdk.js";
        g.defer = true;
        g.async = true;
        s.parentNode.insertBefore(g, s);
        g.onload = function () {
            window.chatwootSDK.run({
                websiteToken: '8hHz6U2ZLJZQYc4nqKbGoFFE',
                baseUrl: BASE_URL
            })
        }
    })(document, "script");

    // 手动解析查询字符串
    function getUrlParams() {
        const queryString = window.location.search.substring(1);
        const params = {};
        if (queryString) {
            const paramPairs = queryString.split('&');
            for (let i = 0; i < paramPairs.length; i++) {
                const pair = paramPairs[i].split('=');
                const key = decodeURIComponent(pair[0]);
                const value = decodeURIComponent(pair[1] || '');
                params[key] = value;
            }
        }
        return params;
    }


    console.log('手动解析获取所有参数:', getUrlParams());
    // 等待Chatwoot初始化完成
    window.addEventListener('chatwoot:ready', function () {
        console.log(11111111111)
        // 设置用户信息
        // if (userIsLoggedIn) { // 替换为您的用户登录检查
        window.$chatwoot.setUser(getUrlParams().id, {
            email: getUrlParams().email,
            name:  getUrlParams().nick
        });
        // }
    });
</script>